package com.gaozhen.demo;

public class Test4 {
    public static void main(String[] args) {
        //数组元素的复制
        //把一个数组中的元素复制到另一个新数组中去
        int[] arr1 = {11,22,33,44};
        //int[] arr2 = arr1;
        int[] arr2 = new int[arr1.length];
        copy(arr1,arr2);
        printArrray(arr1);
        System.out.println("-----------------------------------");
        printArrray(arr2);
    }
    public static void printArrray(int[] arr){
        System.out.print("[");
        for (int i = 0; i < arr.length; i++) {
            System.out.print(i == arr.length-1 ? arr[i] : arr[i] + ",");
        }
        System.out.println("]");
    }
    public  static void copy(int[] arr1,int[] arr2){
        for (int i = 0; i < arr1.length; i++) {
            arr2[i] = arr1[i];
        }
    }
}
